
$(function () {
    //商品零售报表,统计每个商品时间段内的销量
    $("#saleItem_datagrid").datagrid({
        width: 800,
        height: 400,
        //数据来源url
        //url: '/smartAnalysis/saleItemChartJson',
        //列
        columns: [[
            {field: 'productName', title: '商品名称', width: 150},
            {field: 'unit', title: '规格', width: 80},
            {field: 'avgSalePrice', title: '平均售价', width: 80},
            {field: 'totalSaleNumber', title: '销售总数量', width: 80},
            {field: 'totalSaleAmount', title: '销售总金额', width: 80}
        ]],
        //按比例分配列宽以适应表格大小
        fitColumns: true,
        fit: true,
        toolbar: "#tb",
        //斑马线效果
        striped: true,
        //底部分页栏
        pagination: true,
        //显示行号列
        rownumbers: true,
        //只能选择单行数据
        singleSelect: true,
        //指定页面大小的可选数值
        pageList: [10, 15, 20],
        //指定默认的页面大小
        pagesize: 10,

    });

    //页面加载完载入当日数据
    today();

})


function today() {
    var beginDate = new Date(new Date(new Date().toLocaleDateString()).getTime());
    var endDate = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1);
    beginDate = DateUtils.format(beginDate, "yyyy-MM-dd HH:mm:ss");
    endDate = DateUtils.format(endDate, "yyyy-MM-dd HH:mm:ss");
    $("#saleItem_datagrid").datagrid("load", "/smartAnalysis/saleItemChartJson?beginDate=" + beginDate + "&endDate=" + endDate);
}
function yesterday() {
    var beginDate = new Date(new Date(new Date().toLocaleDateString()).getTime() - +24 * 60 * 60 * 1000);
    var endDate = new Date(new Date(new Date().toLocaleDateString()).getTime() - 1);
    beginDate = DateUtils.format(beginDate, "yyyy-MM-dd HH:mm:ss");
    endDate = DateUtils.format(endDate, "yyyy-MM-dd HH:mm:ss");
    $("#saleItem_datagrid").datagrid("load", "/smartAnalysis/saleItemChartJson?beginDate=" + beginDate + "&endDate=" + endDate);

}
function thisweek() {
    var currentDate = new Date(new Date(new Date().toLocaleDateString()).getTime());
    var week = currentDate.getDay();
    var month = currentDate.getDate();
    var millisecond = 1000 * 60 * 60 * 24;
    var minusDay = week != 0 ? week - 1 : 6;
    var monday = new Date(currentDate.getTime() - (minusDay * millisecond));
    var beginDate = DateUtils.format(monday, "yyyy-MM-dd HH:mm:ss");
    var endDate = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1);
    endDate = DateUtils.format(endDate, "yyyy-MM-dd HH:mm:ss");
    $("#saleItem_datagrid").datagrid("load", "/smartAnalysis/saleItemChartJson?beginDate=" + beginDate + "&endDate=" + endDate);

}
function thismonth() {
    var endDate = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1);
    var beginDate = new Date(new Date(new Date().toLocaleDateString()).getTime());
    beginDate.setDate(1);
    beginDate = DateUtils.format(beginDate, "yyyy-MM-dd HH:mm:ss");
    endDate = DateUtils.format(endDate, "yyyy-MM-dd HH:mm:ss");
    $("#saleItem_datagrid").datagrid("load", "/smartAnalysis/saleItemChartJson?beginDate=" + beginDate + "&endDate=" + endDate);
    console.log(beginDate);
    console.log(endDate);
}

function advSearch() {
    var keyword = $("#keyword").textbox("getValue");
    $("#saleItem_datagrid").datagrid("load", {
        keyword: keyword
    });
}
